<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">

    <home-page></home-page>
  </div>
  <script src="./vue.global.js"></script>
  <script src="./axios.js"></script>
  <script>
    const request = axios.create({
      baseURL: 'https://api.it120.cc/conner',
      timeout: 8000,
      headers: {
        token: '111-222-333'
      }
    })
    const { createApp } = Vue;
    const app = createApp({
    });
    const HomePage = {
      template: `
        <div>
          <ul>
            <li v-for="art in arts" :key="art.id">
              <img width="50" :src="art.pic"/>  
              <h4>{{art.title}}</h4>
            </li>  
          </ul>
        </div>
      `,

      data() {
        return {
          arts: [], // 1data中要定义初始值
        }
      },
      methods: {
        fetchArticle() {
          request.post('/cms/news/list/v2', {
            page: 1,
            pageSize: 10
          }).then(res => {
            if(res.data.code === 0) {
              this.arts = res.data.data.result
            }
          })
        }
      },
      created() {
        // 3 在合适生命周期钩子中调用
        this.fetchArticle()
      }
    }

    app.component('HomePage', HomePage)
    app.mount('#app')
  </script>
</body>

</html>